define(function (require, exports, module) {
  'use strict';
  var $ = require('jquery'),
      _ = require('underscore'),
      Backbone = require('backbone'),
      notify = require('js/utils/notify'),
      utils = require('js/utils/tools'),
      helper = require('js/apps/report/common');

  var MetisForbiddenView = Backbone.View.extend({
      events: {
          'click a.onClickSaveDebug': 'saveDebug',
          'click a#btn_add': "addRangeDom",
          'click i.time-range-del': "deleteRangeDom",
          'click #exportBtn': 'doExport'
      },
      initialize: function (options) {
          this.options = options;
          this.s_list = [];
      },
      doExport: function () {
          notify.warning('警告', '导出中，耗时较长请等待...');
          var that = this;
          $.get('/admin/metis_forbidden/?$export=1').done(function (resp) {
              window.location = resp.data.url;
          }).fail(function (data) {
              notify.notifyResp(data);
          });
      },
      addRangeDom: function (e) {
          var rangeHtml = $(".timeRangeTemplate").clone().show().removeClass("timeRangeTemplate");
          $("#div_timeRange").append(rangeHtml);
          return false;
      },
      deleteRangeDom: function (e) {
          e.preventDefault();
          $(e.currentTarget).closest(".inputUid").remove();
          return false;
      },
      saveDebug: function (e) {
          var uids = [];
          $(".inputUid input").each(function(i) {
              if($(this).val() != "") {
                  uids.push($(this).val());
              }
          })
          console.log(uids);
          if(window.confirm('谨慎操作，请再次确认')){
              $.post('/admin/metis_forbidden/', JSON.stringify(uids)).done(function (resp) {
                  var data = resp.data;
                  notify.success('提示', '保存成功！');
              }).fail(function (data) {
                  notify.notifyResp(data);
              });
          }
      },
      render: function () {
          this.$el.html("");
          $(window).scrollTop(0);
          return this;
      },
      renderWithData: function () {
          this.$el.html(this.template({
              s_list: this.s_list,
              options: this.options,
          }));
          return this;
      },
      load: function () {
          var that = this;
          $.get('/admin/metis_forbidden/').done(function (resp) {
              that.s_list = resp.data.list;
              that.renderWithData();
          }).fail(function (data) {
              notify.notifyResp(data);
          });
      }
  });
  exports.List = Backbone.View.extend({
      el: "#content_wrapper",
      template: "op/MetisForbidden.html",
      render: function () {
          var view = new MetisForbiddenView;
          view.template = this.template;
          this.$el.empty();
          this.$el.append(view.render().el);
          view.load();
          return this;
      }
  });

});
